package com.hui.java.Synchronized;

/**
 * TODO: 类锁
 *
 * @author chenth
 * @create 2019-09-07 19:43
 **/
public class SynchronizedClass implements Runnable{

    @Override
    public void run() {
        syncMethod();
    }

    private void syncMethod(){
        synchronized(SynchronizedClass.class){
                System.out.println(Thread.currentThread().getName() );
            System.out.println(Thread.currentThread().getName() + " is finished!");
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public static void main(String[] args) {
        SynchronizedClass synchronizedClass = new SynchronizedClass();
        SynchronizedClass synchronizedClass2 = new SynchronizedClass();
        Thread thread = new Thread(synchronizedClass,"A");
        Thread thread2 = new Thread(synchronizedClass2,"B");
        thread.start();
        thread2.start();
    }
}
